package luogu.rookie;

import java.util.Scanner;

public class P1216_数字金字塔 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] num = new int[N][];
        for (int i = 0; i < N; i++) {
            num[i] = new int[i + 1];
            for (int j = 0; j < i+1; j++) {
                num[i][j] = sc.nextInt();
            }
        }
        //System.out.println(dp(num, 0, 0));
        System.out.println(recursion(num, 0, 0));

    }

    public static int recursion(int[][] triangle, int i, int j){
        int rowIndex = triangle.length;
        if (i == rowIndex - 1){
            return triangle[i][j];
        }else {
            return triangle[i][j] + Math.max(recursion(triangle, i+1, j), recursion(triangle, i+1, j+1));
        }

    }


    public static int dp(int[][] triangle, int i, int j){
        int rowCount = triangle.length;//行数
        int columnCount = triangle[rowCount - 1].length;//最后一行的列数
        int[][] dp = new int[rowCount][columnCount];
        for (int k = 0; k < columnCount; k++) {
            dp[rowCount - 1][k] = triangle[rowCount - 1][k];//初始化最后一行
        }
        for (int k = rowCount - 2; k >=0 ; k--) {
            for (int l = 0; l <= k ; l++) {
                dp[k][l] = triangle[k][l] +Math.max(dp[k+1][l], dp[k+1][l+1]);
            }
        }
        return dp[0][0];
    }

//        int[] states = new int[columnCount];
//        for (int k = 0; k < columnCount; k++){
//            states[k] = triangle[rowCount - 1][k];
//        }
//        for (int row = rowCount - 2; row >= 0; row--){
//            for (int col = 0; col < triangle[row].length; col++){
//                states[col] = triangle[row][col] + Math.max(states[col], states[col + 1]);
//            }
//        }
//        return states[0];








}
